<layout name='Layout/layout_main' />
<script type="text/javascript">
	function add() {
		window.open("{:U('add')}", "_self");
		return false;
	}

	function edit(){
		id = $("li.tbody.active :checkbox").val();
		if (id == undefined) {
			alert("请选择要编辑的联系人");
			return false;
		} else {
			window.open(fix_url("{:U('edit')}?id="+ id), "_self");
		}
	}

	function select_class() {
		winopen("{:U('winpop')}", 600, 400);
	}

	function mark(action){
		if ($("#form_data .table input:checked").length == 0) {
			$("li.tbody.active input:checkbox").attr("checked", true);
		}
		var vars = $("#form_data").serialize();
		switch(action) {
			case "del":
				if(confirm('确定要删除吗?')){
					sendAjax("{:U('mark?action=del')}", vars, function(data) {
						alert(data.info);
						if (data.status){
							$("input[name='material_id[]']:checkbox:checked").each(function() {
								$(this).parents("li").remove();
							})
						}
					});
				}
				break;
			default:
		}
		$("#select_all").attr("checked", false);
	}

	function move_to(val){
		if ($("#form_data .table input:checked").length == 0) {
			$("li.tbody.active input:checkbox").attr("checked", true);
		}
		var vars = $("#form_data").serialize();
		sendAjax("{:U('mark?action=move_folder')}", 'val=' + val + '&' + vars,function(data){
			alert(data.info);
			$("#form_data .table input:checked").each(function(){
				class_name=$(".dropdown-menu #"+val).text();
				$(this).parents("li").find("span.class").text(class_name);
			})
			$("li.tbody input:checkbox").attr("checked", false);
		});
	}

	function export_contact(){
		window.open("{:U('export')}","_blank");
	}

	function import_contact(){
		window.open("{:U('import')}","_self");
	}

	$(document).ready(function() {
		set_return_url();
		
		$("#move_to li").click(function(){
			move_to($(this).attr("id"));
		})

		$(".table input:checkbox").click(function(e) {
			$("li.tbody.active").removeClass("active");
			$("li.tbody input:checked").each(function() {
				$(this).parents("li.tbody").addClass("active");
			})
			e.stopPropagation();
		})

		$("li.tbody").click(function() {
			$("li.tbody.active").removeClass("active");
			$(this).addClass("active");
			$(".table input:checkbox").attr("checked", false);
		})
	}); 
</script>
<div class="doc">
	<form id="form_search" method='post' >
		<div class="row-fluid title">
			<span>资材</span>
			<div class="input-append right">
				<input type="text"  onkeydown="key_search();" name="keyword">
				<a class="btn" type="button" onclick="btn_search();"> <i class="icon-search"></i>
				</a>
				<a class="btn" onclick="open_search();"> <i class="icon-angle-down"></i>
				</a>
			</div>
		</div>
		<div class="row-fluid adv_search">
			<div class="row-fluid adv_search_head">
				<h4 class="left">高级搜索</h4>
				<div class="right text-right">
					<a  class="btn" onclick="adv_search();">搜索</a>
					<a  class="btn" onclick="close_search();">关闭</a>
				</div>
			</div>
			<div class="row-fluid form-horizontal">
				<div class="control-group span6">
					<label class="control-label" for="name">名称+属性：</label>
					<div class="controls">
						<input type="text" id="name" name="name"></div>
				</div>
				<div class="control-group span6">
					<label class="control-label" for="spec">规格：</label>
					<div class="controls">
						<input type="text" id="spec" name="spec" ></div>
				</div>
			</div>
			<div class="row-fluid form-horizontal">
				<div class="control-group span6">
					<label class="control-label" for="mat_no">编号：</label>
					<div class="controls">
						<input type="text" id="mat_no" name="mat_no"></div>
				</div>
				<div class="control-group span6">
					<label class="control-label" for="class_name">分类：</label>
					<div class="controls">
						<input type="hidden" name="class" id="class">
						<div class="input-append">
							<input  type="text" id="class_name" name="class_name" check="require" msg="请输入类别" readonly>
							<button class="btn" type="button"  onclick="select_class()" >选择</button>
						</div>
					</div>
				</div>
			</div>
		</div>
	</form>
	<form id="form_data" name="form_data" method='post'>
		<input type="hidden" name="ajax" id="ajax" value="1">
		<div class="operate row-fluid">
			<div class="left">
				<div class="btn-group">
					<a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
						管理
						<span class="caret"></span>
					</a>
					<ul class="dropdown-menu">
						<li>
							<a onclick="manage_group();">管理组</a>
						</li>
						<li>
							<a onclick="import_contact();">导入</a>
						</li>
						<li>
							<a onclick="export_contact();">导出</a>
						</li>
					</ul>
				</div>
				<a class="btn" onclick="edit();">编辑</a>
				<a class="btn" onclick="mark('del');">删除</a>
				<div class="btn-group" id="move_to">
					<a class="btn dropdown-toggle" data-toggle="dropdown" href="#" >
						转移到
						<span class="caret"></span>
					</a>
					<ul class="dropdown-menu">{$class_list}</ul>
				</div>
			</div>
			<div class="right">
				<a class="btn" onclick="add();">新建</a>
			</div>
		</div>
				<div class="table">
			<ul>
				<li class="thead" style="padding-left:30px">
					<span class="checkbox">
						<input  type="checkbox" id="chk_select_all" value="all" onclick="select_all('material_id[]')"/>
					</span>
					<span class="col-9" >编号</span>
					<span class="col-7 right hidden-phone">积压上线</span>
					<span class="col-7 right hidden-phone">缺货下线</span>
					<span class="col-7 right hidden-phone">初始库存</span>
					<span class="col-7 right hidden-phone">参考售价</span>
					<span class="col-7 right hidden-phone">参考进价</span>
					<span class="col-8 right">分类</span>
					<span class="col-5 right">单位</span>
					<span class="col-8 right">规格</span>
					<div class="auto autocut">名称+属性</div>
				</li>
			<if condition="count($list) eq 0 ">
				<li class="tbody text-center">
					<h3>没找到相应的数据</h3>
				</li>
			</ul>
		</div>
	</form>		
			<else/>
			<foreach name="list" item="vo">
				<li class="tbody"  style="padding-left:30px">
					<div class="data" style="display:none">{$vo.letter}{$vo.mat_no}{$vo.class_name}{$vo.name}</div>
					<span class="checkbox" >
						<input type="checkbox" name="material_id[]" value="{$vo.id}" >
					</span>
					<span class="col-9"  >{$vo.mat_no}&nbsp;</span>
					<span   class="col-7 right hidden-phone text-right">{$vo.max_qty|number_format=###,2}&nbsp;</span>
					<span   class="col-7 right hidden-phone text-right">{$vo.min_qty|number_format}&nbsp;</span>
					<span   class="col-7 right hidden-phone text-right">{$vo.init_qty|number_format}&nbsp;</span>
					<span   class="col-7 right hidden-phone text-right">{$vo.sell_price|number_format}&nbsp;</span>
					<span   class="col-7 right hidden-phone text-right">{$vo.buy_price|number_format}&nbsp;</span>
					<span  class="col-8 right text-center class">{$vo.class_name}&nbsp;</span>
					<span  class="col-5 right text-center">{$vo.unit}&nbsp;</span>
					<span  class="col-8 right">{$vo.spec}&nbsp;</span>
					<div class="auto autocut">{$vo.name}&nbsp;</div>
				</li>
			</foreach>
		</ul>
	</div>
</form>
<div class="page">{$page}</div>
</if>
</div>